﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace RehabilitationRobot
{
    public static class Unity3D
    {
        /// <summary>
        /// 将数据装箱发给Unity3D控件
        /// </summary>
        /// <param name="control">unity3D控件</param>
        /// <param name="strAngle">需发送的数据</param>
        internal static void PackAngleSendToUnity(UnityPlayer.U3Dplayer control, string strAngle)
        {
            control.SendMessage("RobotControl", "UnpackAngleFromWinform", (object)strAngle);   
            /*调用插件提供的数值SendMessage函数发送数据给unity；(object)Value为需要传递的字符串，装箱成object来传递。
            RobotControl为unity中游戏对象名；UnpackAngleFromWinform为该游戏对象上函数名。*/
        }

        /// <summary>
        /// 将double型数组转换为字符串
        /// </summary>
        /// <param name="Array"></param>
        /// <returns></returns>
        public static string DoubArrayToString(double[] Array)  //double型数组，转换并整合成一个字符串，每个数组元素用逗号隔开，用于传递给unity
        {
            string strArray0, strArray1, strArray2, strArray3; //定义double型数组每个元素对应的字符串
            string strArray;   //定义整合成string型之后的数组字符串；其中，数组元素之间用“，”号隔开

            /* Unity3D中是左手坐标系 */
            strArray0 = Array[0].ToString();
            strArray1 = Array[2].ToString();
            strArray2 = Array[1].ToString();
            strArray3 = Array[3].ToString();

            strArray = strArray0 + "," + strArray1 + "," + strArray2 + "," + strArray3; //整合字符串成一个，用逗号隔开每个数组元素
            return strArray;
        }
    }
}
